<template>
 <el-input :style="{width:setW+'px'}" v-model="setVal"  placeholder="" disabled>
        <svg-icon slot="append" :icon-class="icon" :clickable="iconClickFlag" @click="iconClick"></svg-icon>
    </el-input>
</template>
<script>
export default {
  props: {
    icon: String,
    rawData: Object | Array,
    field: String,
    type: String,
    iconClickFlag: {
      type: Boolean,
      default: true
    },
    setW: String
  },
  methods: {
    iconClick(event) {
      this.$emit("click", this.rawData[this.field]);
    }
  },
  computed: {
    setVal() {
      var val = "";

      var isStr;

      if (this.rawData[this.field]) {
        if (isArray(this.rawData[this.field])) {
          isStr = isString(this.rawData[this.field][0]);
          for (let i = 0; i < this.rawData[this.field].length; i++) {
            if (isStr) {
              if (i == this.rawData[this.field].length - 1) {
                val += getValueByKey(this.type, this.rawData[this.field][i]);
              } else {
                val +=
                  getValueByKey(this.type, this.rawData[this.field][i]) + ",";
              }
            } else {
              if (i == this.rawData[this.field].length - 1) {
                val += this.rawData[this.field][i][this.type];
              } else {
                val += this.rawData[this.field][i][this.type] + ",";
              }
            }
          }
          val = val.toString();
        } else {
          val = this.rawData[this.field];
        }
      }

      if (isArray(val)) {
        val = "";
      }

      return val;
    }
  }
};
</script>
